﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace iHub
{
    public partial class selectemployee : Form
    {
        public selectemployee()
        {
            InitializeComponent();
            this.FormClosing += new FormClosingEventHandler(Form_Closing);
        }

        private void Form_Closing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                DialogResult msg = MessageBox.Show("Closing this window will not save the entered Employee ID. Proceed Anyway?","Proceed",MessageBoxButtons.YesNo,MessageBoxIcon.Warning);

                if (msg == DialogResult.Yes)
                {
                    this.Dispose();
                }
                else
                {
                    e.Cancel = true;
                }
            }
        }

        private void enterid_Click(object sender, EventArgs e)
        {
            EmployeeManager empm = new EmployeeManager();
            int id;

            try
            {
                if (!eid.Text.Equals(""))
                {
                    id = Convert.ToInt32(eid.Text);

                    if (empm.verifyEmployee(id))
                    {
                        importedfile.eid = id;
                        importedfile.ename = empm.getEmployeeName(id);
                        this.Dispose();
                    }
                    else
                    {
                        MessageBox.Show("Employee ID is invalid, no records found for entered ID", "Not Found", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else
                {
                    MessageBox.Show("Please enter a valid value", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.ToString(), "Fatal", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
